]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
LayoutManager: add a ClutterConstraint for tracking monitor sizes
authorGiovanni Campagna <gcampagna@src.gnome.org>
Tue, 14 Aug 2012 13:37:12 +0000 (15:37 +0200)
committerGiovanni Campagna <gcampagna@src.gnome.org>
Thu, 16 Aug 2012 19:45:21 +0000 (21:45 +0200)
Instead of connecting manually to LayoutManager, or using ShellGenericContainer,
make a ClutterConstraint subclass that can track automatically
a specific monitor index, or the primary monitor.

https://bugzilla.gnome.org/show_bug.cgi?id=681743

js/ui/layout.js

index a4da201a37695c174895e7979a902f97e722329b..266d22cacac0f502d166684b4451c19de296bf58 100644 (file)
@@ -1,6 +1,7 @@
 // -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
 
 const Clutter = imports.gi.Clutter;
+const GObject = imports.gi.GObject;
 const Lang = imports.lang;
 const Mainloop = imports.mainloop;
 const Meta = imports.gi.Meta;
@@ -17,6 +18,79 @@ const HOT_CORNER_ACTIVATION_TIMEOUT = 0.5;
 const STARTUP_ANIMATION_TIME = 0.2;
 const KEYBOARD_ANIMATION_TIME = 0.5;
 
+const MonitorConstraint = new Lang.Class({
+    Name: 'MonitorConstraint',
+    Extends: Clutter.Constraint,
+    Properties: {'primary': GObject.ParamSpec.boolean('primary', 
+                                                      'Primary', 'Track primary monitor',
+                                                      GObject.ParamFlags.READABLE | GObject.ParamFlags.WRITABLE,
+                                                      false),
+                 'index': GObject.ParamSpec.int('index',
+                                                'Monitor index', 'Track specific monitor',
+                                                GObject.ParamFlags.READABLE | GObject.ParamFlags.WRITABLE,
+                                                -1, 64, -1)},
+
+    _init: function(props) {
+        this._primary = false;
+        this._index = -1;
+
+        this.parent(props);
+    },
+
+    get primary() {
+        return this._primary;
+    },
+
+    set primary(v) {
+        this._primary = v;
+        if (this.actor)
+            this.actor.queue_relayout();
+        this.notify('primary');
+    },
+
+    get index() {
+        return this._index;
+    },
+
+    set index(v) {
+        this._index = v;
+        if (this.actor)
+            this.actor.queue_relayout();
+        this.notify('index');
+    },
+
+    vfunc_set_actor: function(actor) {
+        if (actor) {
+            if (!this._monitorsChangedId) {
+                this._monitorsChangedId = Main.layoutManager.connect('monitors-changed', Lang.bind(this, function() {
+                    this.actor.queue_relayout();
+                }));
+            }
+        } else {
+            if (this._monitorsChangedId)
+                Main.layoutManager.disconnect(this._monitorsChangedId);
+            this._monitorsChangedId = 0;
+        }
+
+        this.parent(actor);
+    },
+
+    vfunc_update_allocation: function(actor, actorBox) {
+        if (!this._primary && this._index < 0)
+            return;
+
+        let monitor;
+        if (this._primary) {
+            monitor = Main.layoutManager.primaryMonitor;
+        } else {
+            let index = Math.max(this._index, Main.layoutManager.monitors.length);
+            monitor = Main.layoutManager.monitors[index];
+        }
+
+        actorBox.init_rect(monitor.x, monitor.y, monitor.width, monitor.height);
+    }
+});
+
 const LayoutManager = new Lang.Class({
     Name: 'LayoutManager',